package com.yueka.service.Impl;

import com.yueka.mapper.ClassroomMapper;
import com.yueka.pojo.classroom.Classroom;
import com.yueka.service.ClassroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ClassroomServiceImpl implements ClassroomService {
    @Autowired
    private ClassroomMapper classroomMapper;

    @Override
    public List<Classroom> list() {
        return classroomMapper.list();
    }

    @Override
    public void insert(Classroom classroom) {
        classroom.setCreateTime(LocalDateTime.now());
        classroom.setUpdateTime(LocalDateTime.now());
        classroomMapper.insert(classroom);
    }

    @Override
    public void update(Classroom classroom) {
        classroom.setUpdateTime(LocalDateTime.now());
        classroomMapper.update(classroom);
    }

    @Override
    public void delete(Integer id) {
        if (classroomMapper.isUsed(id) > 0){
            throw new RuntimeException("该教室已被使用，不能删除！");
        }
        classroomMapper.delete(id);
    }
}
